/*
 * Group 3, User Interface Programming II (vt11)
 * Pooya | Flora | Monica | Can
 */
package vical.model;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * The model to represent a myDate, could be used by DayView. It
 * includes a myDate and the events related with this single myDate.
 *
 * @author Can
 */
public class DayModel {

    private List<Entry> entries;
    private int year;
    private int month;
    private int date;

    public DayModel(List<Entry> entries, int year, int month, int date) {
        this.entries = entries;
        this.year = year;
        this.month = month;
        this.date = date;
    }

    public DayModel(List<Entry> entries, Calendar date) {
        this.entries = entries;
        this.year = date.get(Calendar.YEAR);
        this.month = date.get(Calendar.MONTH);
        this.date = date.get(Calendar.DATE);
    }

    public List<Entry> getEntries() {
        Calendar myDate = Calendar.getInstance();
        myDate.set(year, month, date);
        return getEntriesByDate(myDate);
    }

    private List<Entry> getEntriesByDate(Calendar date) {
        List<Entry> dayEntries = new ArrayList<Entry>();
        for (Entry entry : this.entries) {
            if (entry.isDateContained(date)) {
                dayEntries.add(entry);
            }
        }
        return dayEntries;
    }

    // return all-day entries if isAllDay == true
    // return NOT all-day entries if isAllDay == false
    public List<Entry> getAllDayEntries(boolean isAllDay) {
        List<Entry> allDayEntries = new ArrayList<Entry>();
        for (Entry entry : this.getEntries()) {
            if (entry.isAllday() == isAllDay) {
                allDayEntries.add(entry);
            }
        }
        return allDayEntries;
    }
}
